<template>
  <div class="hotMusic">
    <div class="hototop">
      <div class="hotopt">
        <div class="hotopic"></div>

        <div
          class="time"
        >更新日期：{{nowDate.getMonth()+1|formatDateAndMonth}}月{{nowDate.getDate()|formatDateAndMonth}}日</div>
      </div>
    </div>
    <songs :musicList="musicList" :showIndex="true" v-if="musicList.length" /><!--:musicList="musicList"就是活的 如果不写:就是传的是musicList字符串-->
  </div>
</template>
 
<script>
import { getTopList } from "@/api/top.js"; //导入封装的接口
import { formatDateAndMonth } from "@/utils/filters/date";
import songs from "./songs"; //封装的方法调用 然后在components 申明 然后以<songs/> 标签名进行使用
export default {
  name: "vueName",
  data() {
    return {
      musicList: [],
      nowDate: new Date()
    };
  },
  components: {
    songs
  },
  filters: {
    formatDateAndMonth
  },
  created() {
    getTopList(1).then(res => {
      //.then方法调用接口函数 res是返回的接口数据
      res.data.playlist.tracks.some((item, index) => {
        //console.log(item)
        if (index < 20) {
          this.musicList[index] = {
            title: item.name,
            dsc: item.al.name,
            al: item.alia[0],
            id: item.id,
            picUrl: item.al.picUrl
          };
          let authors = [];
          item.ar.forEach((item1, index1) => {
            authors.push(item1.name);
          });
          this.musicList[index].authors = authors.join("/");
        } else {
          return true;
        }
      });

      this.$forceUpdate();
    });
  }
};
</script>

<style scoped lang = "scss">
.hotMusic {
  width: 100%;
  .hototop {
    width: 100%;
    padding-top: 38.9%;
    background: url("~assets/img/hot_music_bg_2x.jpg") no-repeat;
    background-size: contain;
    position: relative;
    &::after {
      content: " ";
      position: absolute;
      left: 0;
      top: 0;
      right: 0;
      bottom: 0;
      z-index: 1;
      background-color: rgba(0, 0, 0, 0.2);
    }
    .hotopt {
      height: 100%;
      position: absolute;
      display: flex;
      justify-content: center;
      flex-direction: column; /*当我们display:flex 的时候 默认 flex-direction: row 也就是X是主轴 此时justify-content代表X轴 align-items为Y轴
      如果改变主轴承为 colum  那么此时的justify-content为Y轴  align-items 为X抽 简单一点说就是默认主轴修改为Y 原先设置的justify-content align-items
      里面的值对调
      */
      top: 0;
      /* width: 100%; */
      margin-left: 20px;
      .hotopic {
        z-index: 2;
        width: 100%;
        background: url("~assets/img/index_icon_2x.png") no-repeat -24px -30px;
        background-size: 166px 97px;
        width: 142px;
        height: 67px;
      }
      .time {
        width: 100%;
        color: rgba(255, 255, 255, 0.8);
        z-index: 2;
        margin-top: 10px;
      }
    }
  }
}
</style>